<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /**
     * @param {string[]} strs
     * @return {string[][]}
     */
    var groupAnagrams = function(strs) {
        if(strs.length === 1) {
            return [strs];
        }
        let obj = {}
        strs.forEach(str => {
                let flag = false;
                for (let key in obj) {
                    // 分两种，存在或者不存在
                    if (isAnagrams(str, key)) {
                        console.log(str, key)
                        // obj[key].push(str);
                        flag = true;
                    }
                    else {
                        if (!flag) {
                            console.error(str)
                            obj[str] = [str];
                        }
                    }
                }
        })
        function isAnagrams(str1, str2) {
            if (str1.length !== str2.length) {
                return false;
            }
            let arr1 = str1.split('').sort().join("");
            let arr2 = str2.split('').sort().join("");
            console.log(arr1.toString(), str2,arr1.toString() === arr2.toString())
            return arr1.toString() === arr2.toString();
        }
        return obj;
    };
    console.log(groupAnagrams([ "tea", "tan","nat"]))
</script>
</body>
</html>
